package com.example.smart.utils

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.example.lib.constants.JumpConstants
import com.example.smart.data.AnimalData
import com.example.smart.ui.activity.MainActivity
import com.example.smart.ui.activity.SearchActivity
import com.example.smart.ui.activity.animal.AddAnimalActivity
import com.example.smart.ui.activity.animal.AddAnimalChooseActivity
import com.example.smart.ui.activity.animal.AddAnimalQrCodeActivity
import com.example.smart.ui.activity.chat.ChatActivity
import com.example.smart.ui.activity.chat.ChatListActivity
import com.example.smart.ui.activity.course.CourseDetailsActivity
import com.example.smart.ui.activity.course.CourseDone1Activity
import com.example.smart.ui.activity.course.CourseDone2Activity
import com.example.smart.ui.activity.guide.GuideFirstActivity
import com.example.smart.ui.activity.guide.GuideSecondActivity
import com.example.smart.ui.activity.guide.GuideThirdActivity
import com.example.smart.ui.activity.guide.GuideZeroActivity
import com.example.smart.ui.activity.home.AiConversationActivity
import com.example.smart.ui.activity.home.DayTaskActivity
import com.example.smart.ui.activity.home.DeviceActivity
import com.example.smart.ui.activity.home.EverydayTestActivity
import com.example.smart.ui.activity.home.FenceActivity
import com.example.smart.ui.activity.home.JzActivity
import com.example.smart.ui.activity.home.JzDetailsActivity
import com.example.smart.ui.activity.home.MineActivity
import com.example.smart.ui.activity.home.MyOrderActivity
import com.example.smart.ui.activity.home.MySheepActivity
import com.example.smart.ui.activity.home.SheepListActivity
import com.example.smart.ui.activity.home.NavigationActivity
import com.example.smart.ui.activity.today_circle.PostActivity
import com.example.smart.ui.activity.home.PreventionActivity
import com.example.smart.ui.activity.home.PreventionDetailsActivity
import com.example.smart.ui.activity.home.QuestionActivity
import com.example.smart.ui.activity.home.RankActivity
import com.example.smart.ui.activity.home.ReservationActivity
import com.example.smart.ui.activity.home.SheepMapActivity
import com.example.smart.ui.activity.today_circle.TodayCircleActivity
import com.example.smart.ui.activity.home.UpdateSheepActivity
import com.example.smart.ui.activity.home.VaccinesDetailsActivity
import com.example.smart.ui.activity.home.VaccinesListActivity
import com.example.smart.ui.activity.home.VaccinesPointActivity
import com.example.smart.ui.activity.home.VaccinesPointDetailsActivity
import com.example.smart.ui.activity.home.VideoActivity
import com.example.smart.ui.activity.home.YsActivity
import com.example.smart.ui.activity.login.AccountLoginActivity
import com.example.smart.ui.activity.login.LoginChooseActivity
import com.example.smart.ui.m.MLoginChooseActivity
import com.example.smart.ui.activity.login.WelcomeActivity
import com.example.smart.ui.activity.scan.ScanFullActivity
import com.example.smart.ui.activity.today_circle.TodayCircleDetailsActivity
import com.example.smart.ui.m.MAddAnimalActivity
import com.example.smart.ui.m.MAddAnimalChooseActivity
import com.example.smart.ui.m.MAddAnimalQrCodeActivity
import com.example.smart.ui.m.MAiConversationActivity
import com.example.smart.ui.m.MEverydayTestActivity
import com.example.smart.ui.m.MMainActivity
import com.example.smart.ui.m.MMineActivity
import com.example.smart.ui.m.MTodayCircleActivity
import com.example.smart.ui.m.MVaccinesListActivity
import com.example.smart.ui.m.MPreventionActivity
import com.example.smart.ui.m.MPreventionDetailsActivity
import kotlin.jvm.java

object DisplayUtils {
    var type = 0

    fun toGuide0(activity: Activity) {
        start(activity, GuideZeroActivity::class.java, isNeedFinish = true)
    }

    fun toGuide1(activity: Activity) {
        start(activity, GuideFirstActivity::class.java, isNeedFinish = true)
    }

    fun toGuide2(activity: Activity) {
        start(activity, GuideSecondActivity::class.java, isNeedFinish = true)
    }

    fun toGuide3(activity: Activity) {
        start(activity, GuideThirdActivity::class.java, isNeedFinish = true)
    }

    fun toMain(activity: Activity, index: Int = -1, isNeedFinish: Boolean = true) {
        if (type == 0) {
            start(activity, MainActivity::class.java, isNeedFinish = isNeedFinish, bundle = Bundle().also {
                it.putInt(JumpConstants.HOME_INDEX, index)
            })
        } else {
            start(activity, MMainActivity::class.java, isNeedFinish = isNeedFinish, bundle = Bundle().also {
                it.putInt(JumpConstants.HOME_INDEX, index)
            })
        }
    }

    fun toWelcome(activity: Activity) {
        start(activity, WelcomeActivity::class.java, isNeedFinish = true)
    }

    fun toLoginChoose(activity: Activity) {
        if (type == 0) {
            start(activity, LoginChooseActivity::class.java, isNeedFinish = true)
        } else {
            start(activity, MLoginChooseActivity::class.java, isNeedFinish = true)
        }
    }

    fun toAccountLogin(activity: Activity, isNeedFinish: Boolean = true) {
        start(activity, AccountLoginActivity::class.java, isNeedFinish = isNeedFinish)
    }

    fun toAddAnimal(activity: Activity) {
        if (type == 0) {
            start(activity, AddAnimalActivity::class.java)
        } else {
            start(activity, MAddAnimalActivity::class.java)
        }
    }

    fun toAddAnimal(activity: Activity, type: Int, data: AnimalData) {
        start(activity, AddAnimalActivity::class.java, bundle = Bundle().also {
            it.putInt(JumpConstants.ID, type)
            it.putSerializable(JumpConstants.Bean, data)
        })
    }

    fun toPrevention(activity: Activity?) {
        if (type == 0) {
            start(activity, PreventionActivity::class.java)
        } else {
            start(activity, MPreventionActivity::class.java)
        }
    }

    fun toPreventionDetails(activity: Activity?) {
        if (type == 0) {
            start(activity, PreventionDetailsActivity::class.java)
        } else {
            start(activity, MPreventionDetailsActivity::class.java)
        }
    }

    fun toAddAnimalChoose(activity: Activity) {
        if (type == 0) {
            start(activity, AddAnimalChooseActivity::class.java)
        } else {
            start(activity, MAddAnimalChooseActivity::class.java)
        }
    }

    fun toAddAnimalQrCode(activity: Activity) {
        if (type == 0) {
            start(activity, AddAnimalQrCodeActivity::class.java, isNeedFinish = true)
        } else {
            start(activity, MAddAnimalQrCodeActivity::class.java, isNeedFinish = true)
        }
    }

    fun toScan(activity: Activity) {
        start(activity, ScanFullActivity::class.java)
    }

    fun toVaccinesList(activity: Activity?) {
        if (type == 0) {
            start(activity, VaccinesListActivity::class.java)
        } else {
            start(activity, MVaccinesListActivity::class.java)
        }
    }

    fun toVaccinesDetails(activity: Activity?) {
        start(activity, VaccinesDetailsActivity::class.java)
    }

    fun toReservation(activity: Activity?) {
        start(activity, ReservationActivity::class.java)
    }

    fun toVaccinesPoint(activity: Activity?) {
        start(activity, VaccinesPointActivity::class.java)
    }

    fun toVaccinesPointDetails(activity: Activity?, type: Int) {
        start(activity, VaccinesPointDetailsActivity::class.java, bundle = Bundle().also {
            it.putInt(JumpConstants.ID, type)
        })
    }

    fun toNavigation(activity: Activity?) {
        start(activity, NavigationActivity::class.java)
    }

    fun toSheepMap(activity: Activity?) {
        start(activity, SheepMapActivity::class.java)
    }

    fun toSheepList(activity: Activity?, id: Int = 0) {
        start(activity, SheepListActivity::class.java, bundle = Bundle().also {
            it.putInt(JumpConstants.ID, id)
        })
    }

    fun toMySheep(activity: Activity?) {
        start(activity, MySheepActivity::class.java)
    }

    fun toOrder(activity: Activity?) {
        start(activity, MyOrderActivity::class.java)
    }

    fun toFence(activity: Activity?) {
        start(activity, FenceActivity::class.java)
    }

    fun toUpdateSheep(activity: Activity?, id: Int) {
        start(activity, UpdateSheepActivity::class.java, bundle = Bundle().also {
            it.putInt(JumpConstants.ID, id)
        })
    }

    fun toAiConversation(activity: Activity?) {
        if (type == 0) {
            start(activity, AiConversationActivity::class.java)
        } else {
            start(activity, MAiConversationActivity::class.java)
        }
    }

    fun toVideo(activity: Activity?, url: String) {
        start(activity, VideoActivity::class.java, bundle = Bundle().also {
            it.putString(JumpConstants.ID, url)
        })
    }

    fun toCommunity(activity: Activity?) {
        if (type == 0) {
            start(activity, TodayCircleActivity::class.java)
        } else {
            start(activity, MTodayCircleActivity::class.java)
        }
    }

    fun toCommunityDetails(activity: Activity?, type: Int) {
        start(activity, TodayCircleDetailsActivity::class.java, bundle = Bundle().also {
            it.putInt(JumpConstants.ID, type)
        })
    }

    fun toMine(activity: Activity?) {
        if (type == 0) {
            start(activity, MineActivity::class.java)
        } else {
            start(activity, MMineActivity::class.java)
        }

    }

    fun toEverydayTest(activity: Activity?) {
        if (type == 0) {
            start(activity, EverydayTestActivity::class.java)
        } else {
            start(activity, MEverydayTestActivity::class.java)
        }
    }

    fun toQuestion(activity: Activity?) {
        start(activity, QuestionActivity::class.java)
    }

    fun toRank(activity: Activity?) {
        start(activity, RankActivity::class.java)
    }

    fun toDeviceManager(activity: Activity?) {
        start(activity, DeviceActivity::class.java)
    }

    fun toCourseDetails(activity: Activity?) {
        start(activity, CourseDetailsActivity::class.java)
    }

    fun toCourseDone1(activity: Activity?) {
        start(activity, CourseDone1Activity::class.java, isNeedFinish = true)
    }

    fun toCourseDone2(activity: Activity?) {
        start(activity, CourseDone2Activity::class.java, isNeedFinish = true)
    }

    fun toDayTask(activity: Activity?) {
        start(activity, DayTaskActivity::class.java)
    }

    fun toChatList(activity: Activity?) {
        start(activity, ChatListActivity::class.java)
    }

    fun toChat(activity: Activity?, type: Int) {
        start(activity, ChatActivity::class.java, bundle = Bundle().also {
            it.putInt(JumpConstants.ID, type)
        })
    }

    fun toSearch(activity: Activity?) {
        start(activity, SearchActivity::class.java)
    }

    fun toJz(activity: Activity?) {
        start(activity, JzActivity::class.java)
    }

    fun toJzDetails(activity: Activity?) {
        start(activity, JzDetailsActivity::class.java)
    }

    fun toYsDetails(activity: Activity?) {
        start(activity, YsActivity::class.java, isNeedFinish = true)
    }

    fun toPost(activity: Activity?) {
        start(activity, PostActivity::class.java)
    }


    /**
     * 发起跳转
     * @param android.R.attr.path 路径
     * @param bundle 参数
     * @param isNeedFinish 是否需要结束上个页面
     */
    private fun start(activity: Activity?,
        clazz: Class<*>,
        bundle: Bundle? = null,
        isNeedFinish: Boolean = false,
        requestCode: Int = -1) {
        activity?.let {
            val intent = Intent(it, clazz)
            if (bundle != null) {
                intent.putExtras(bundle)
            }
            if (requestCode != -1) {
                it.startActivityForResult(intent, requestCode)
            } else {
                it.startActivity(intent)
            }
            if (isNeedFinish) {
                it.finish()
            }
        }
    }
}